package com.middleware.mq;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class Producer {

    public static void main(String[] args) throws Exception{

        //1. 创建连接工厂
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        //2. 创建连接 并 开启
        Connection connection = connectionFactory.createConnection();
        connection.start();
        //3. 创建Session
        Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
        //4. 创建消息目的地
        Destination destination = session.createQueue("weixin-Queue");
        //5. 创建生产者
        MessageProducer producer = session.createProducer(destination);
        //6. 发送消息
        TextMessage textMessage = session.createTextMessage("Hello,MQ3");
        producer.send(textMessage);
        //7. 释放资源
        producer.close();
        session.close();
        connection.close();
    }

}
